package pers.linkong.asr.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import pers.linkong.asr.domain.ImageBean;
import pers.linkong.asr.domain.StudentBean;
import pers.linkong.asr.mapper.StudentMapper;

@Service
// Service组件
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE, readOnly = false)
public class StudentService {
	@Autowired
	private StudentMapper studentMapper;

	// 增
	public void addStudent(StudentBean student) throws Exception {
		this.studentMapper.addStudent(student);
		this.studentMapper.addStudentClass(student);
		System.out.println("添加学生：" + student.getSid());
		// throw new RuntimeException();
	}

	// 删
	public void deleteStudent(int sid) throws Exception {
		this.studentMapper.deleteStudentClass(sid);
		this.studentMapper.deleteStudent(sid);
		System.out.println("删除学生：" + sid);
	}

	// 查
	public StudentBean getStudentById(int id) throws Exception {
		StudentBean student = studentMapper.getStudentById(id);
		System.out.println("查询学生：" + student.getSname());
		return student;
	}
	
	// 查
	public List<ImageBean> getImageById(int id) throws Exception {
		System.out.println("查询图片：" + id);
		List<ImageBean> imagelist = studentMapper.getImageById(id);
		return imagelist;
	}
	
	// 改
	public void updateStudent(StudentBean student) throws Exception {
		this.studentMapper.updateStudent(student);
		this.studentMapper.updateStudentClass(student);
		System.out.println("修改学生：" + student.getSname());
	}

	// 分页
	public List<StudentBean> findStudentByPage(StudentBean student, long start,
			long limit) throws Exception {
		List<StudentBean> studentBeans = this.studentMapper.findStudentByPage(student, start, limit);
		return studentBeans;
	}
	
	// 统计
	public long getStudentCount(StudentBean student) throws Exception {
		return this.studentMapper.getStudentCount(student);
	}
	
}
